'''
insert sort 升降序排序只用改变key和array[j]的值
insert sort 是有循环的拍改变key的值
'''
def Initialise():
    global NumberOfJobs
    NumberOfJobs = 0
    for i in range(100):
        Jobs.append([-1,-1])


'''
Checks if array is full -1
Incrementing NumberOfJobs -1
'''
def AddJob(job_number,priority):
    for i in range(100):
        if Jobs[i][0] == -1 and Jobs[i][1] == -1:
            Jobs[i][0] = job_number
            Jobs[i][1] = priority
            print("Added")
            return
    print("Not added")


#M: -3
def InsertionSort():
    length = len(Jobs)
    key = 0
    for i in range(1,length):
        j = i - 1
        key = Jobs[i][1]
        while j >= 0 and key < Jobs[j][1]:
            Jobs[j + 1][1] = Jobs[j][1]
            j -= 1
        Jobs[j + 1][1] = key

# M： -1
def PrintArray():
    for i in range(100):
        print(f"{Jobs[i][0]} priority {Jobs[i][1]}")



if __name__ == '__main__':
    global NumberOfJobs
    Jobs = []
    NumberOfJobs = -1
    Initialise()
    AddJob(12,10)
    AddJob(526,9)
    AddJob(33,8)
    AddJob(12,9)
    AddJob(78,1)
    InsertionSort()
    PrintArray()